<?php View::render('admin/layouts/meta'); ?>
<link rel="stylesheet" type="text/css" href="<?php echo Router::getBaseUrl();?>/assets/js/webuploader.css" />
<body>
<article class="page-container">
	<form action="" method="post" class="form form-horizontal" id="form-member-add">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" name="name" value="<?php echo $role_info?$role_info['name']:'';?>" />
			</div>
		</div>
        <div class="row cl">
			<ul class="tpl-task-list ml-20">
                <?php if($node_list){foreach ($node_list as $row){?>
                <li>
                    <div class="task-title ml-20 mb-20">
                        <span class="task-title-sp">分组:<?php echo $row['name'];?> <label style="display: none"><input type="checkbox" name="node[]" value="<?php echo $row['id'];?>" class="node_row" <?php echo in_array($row['id'], $role_node_list)?'checked="checked"':'';?>/> 选择</label></span>
                    </div>
                </li>
                <?php if($row['child']) {foreach ($row['child'] as $item){?>
                    <li>
                        <div class="task-title mb-10" style="margin-left:100px;">
                            <span class="task-title-sp">
                                <label><input type="checkbox" name="node[]" value="<?php echo $item['id'];?>" rel="<?php echo $row['id'];?>" class="node_item node_row_<?php echo $row['id'];?>" <?php echo in_array($item['id'], $role_node_list)?'checked="checked"':'';?>/> <?php echo $item['name'];?> </label>
                                <?php if($item['child']) {?>
                                <br/>
                                <span style="margin-left:50px">
                                <?php foreach ($item['child'] as $cell){?>
                                    <label><input type="checkbox" name="node[]" value="<?php echo $cell['id'];?>" rel="<?php echo $item['id'];?>" class="node_cell node_row_<?php echo $row['id'];?> node_item_<?php echo $item['id'];?>" <?php echo in_array($cell['id'], $role_node_list)?'checked="checked"':'';?>/> <?php echo $cell['name'];?> </label>
                                <?php }?>
                                </span>
                                <?php }?>
                            </span>
                        </div>
                    </li>
                <?php }}?>
                <?php }}?>
            </ul>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input type="hidden" name="role_id" value="<?php echo $role_info?$role_info['role_id']:0;?>" />
                <input class="btn btn-primary radius" type="button" id="j_submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>
</body>
<?php View::render('admin/layouts/footer'); ?>
<script type="text/javascript" src="<?php echo Router::getBaseUrl();?>/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl();?>/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="<?php echo Router::getBaseUrl();?>/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="<?php echo Router::getBaseUrl();?>/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl();?>/assets/js/webuploader.min.js"></script>
<script type="text/javascript">
$(function(){
  $('#j_submit').click(function () {
            var $btn = $(this)
            $btn.button('loading');
            $.post('/admin_admin/role_edit', $('form').serialize(), function (result) {
                if (result.status == 200) {
                    layer.msg(result.msg, {
                        icon: 1, //0-6
                        //anim:2,
                        skin: 'u-msg',
                        time: 1200,
                    },function(){
                        var index = parent.layer.getFrameIndex(window.name); 
                        parent.layer.close(index);
                        parent.window.location.href=parent.window.location.href;
                    });

                }else{
                    layer.msg(result.msg, {
                        icon: 0, //0-6
                        //anim:2,
                        skin: 'u-msg',
                        time: 3000,
                    }, function () {
                        //do things
                    });
                }
                $btn.button('reset');
            }, 'json');
            return;
        });
        
        //全选
        $(".node_row").each(function(){
          $(this).on("click",function(){
            var id = $(this).attr('value');
            var checked = !!$(this).is(":checked");
            $(".node_row_"+id).prop('checked',checked);
          })
        });
        $(".node_item").each(function(){
          $(this).on("click",function(){
            var pid = $(this).attr('rel');
            var id = $(this).attr('value');
            var checked = !!$(this).is(":checked");
            if(checked==true) {
                $('input[value="'+pid+'"]').prop('checked', checked);
            }
            $(".node_item_"+id).prop('checked',checked);
           
          })
        });
        
        $(".node_cell").each(function(){
          $(this).on("click",function(){
            var pid = $(this).attr('rel');
            var checked = !!$(this).is(":checked");
            if(checked==true) {
                $('input[value="'+pid+'"]').prop('checked', true);
            }
          })
        });
});
</script>
</html>